From 6ca8eebc9bf8131c6adb05b2da5580cd10a9ef5b Mon Sep 17 00:00:00 2001 From: "smh22@firebug.cl.cam.ac.uk" Date: Fri, 7 Apr 2006 15:58:00 +0100 Subject: [PATCH] Additional sanity / compatability checks during guest build. Signed-off-by: Steven Hand --- tools/libxc/xc_linux_build.c | 38 +++++++++++++++++++++++++++++++----- tools/libxc/xc_load_elf.c | 15 ++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/tools/libxc/xc_linux_build.c b/tools/libxc/xc_linux_build.c index 2dbcf9fac6..34338884fe 100644 --- a/tools/libxc/xc_linux_build.c +++ b/tools/libxc/xc_linux_build.c @@ -110,10 +110,10 @@ static int parse_features( if ( i == XENFEAT_NR_SUBMAPS*32 ) { - ERROR("Unknown feature \"%.*s\".\n", (int)(p-feats), feats); + ERROR("Unknown feature \"%.*s\".", (int)(p-feats), feats); if ( req ) { - ERROR("Kernel requires an unknown hypervisor feature.\n"); + ERROR("Kernel requires an unknown hypervisor feature."); return -EINVAL; } } @@ -579,6 +579,31 @@ static int setup_guest(int xc_handle, return -1; } #else /* x86 */ + +/* Check if the platform supports the guest kernel format */ +static int compat_check(int xc_handle, struct domain_setup_info *dsi) +{ + xen_capabilities_info_t xen_caps = ""; + + if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0) { + ERROR("Cannot determine host capabilities."); + return 0; + } + + if (strstr(xen_caps, "xen-3.0-x86_32p")) { + if (!dsi->pae_kernel) { + ERROR("Non PAE-kernel on PAE host."); + return 0; + } + } else if (dsi->pae_kernel) { + ERROR("PAE-kernel on non-PAE host."); + return 0; + } + + return 1; +} + + static int setup_guest(int xc_handle, uint32_t dom, const char *image, unsigned long image_size, @@ -635,10 +660,13 @@ static int setup_guest(int xc_handle, if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 ) { - PERROR("Guest OS must load to a page boundary.\n"); + PERROR("Guest OS must load to a page boundary."); goto error_out; } + if (!compat_check(xc_handle, &dsi)) + goto error_out; + /* Parse and validate kernel features. */ p = strstr(dsi.xen_guest_string, "FEATURES="); if ( p != NULL ) @@ -647,7 +675,7 @@ static int setup_guest(int xc_handle, supported_features, required_features) ) { - ERROR("Failed to parse guest kernel features.\n"); + ERROR("Failed to parse guest kernel features."); goto error_out; } @@ -659,7 +687,7 @@ static int setup_guest(int xc_handle, { if ( (supported_features[i]&required_features[i]) != required_features[i] ) { - ERROR("Guest kernel does not support a required feature.\n"); + ERROR("Guest kernel does not support a required feature."); goto error_out; } } diff --git a/tools/libxc/xc_load_elf.c b/tools/libxc/xc_load_elf.c index 94c5c8708c..ee4b2f9a71 100644 --- a/tools/libxc/xc_load_elf.c +++ b/tools/libxc/xc_load_elf.c @@ -69,6 +69,21 @@ static int parseelfimage(const char *image, return -EINVAL; } + if ( +#if defined(__i386__) + (ehdr->e_ident[EI_CLASS] != ELFCLASS32) || + (ehdr->e_machine != EM_386) || +#elif defined(__x86_64__) + (ehdr->e_ident[EI_CLASS] != ELFCLASS64) || + (ehdr->e_machine != EM_X86_64) || +#endif + (ehdr->e_ident[EI_DATA] != ELFDATA2LSB) || + (ehdr->e_type != ET_EXEC) ) + { + ERROR("Kernel not a Xen-compatible Elf image."); + return -EINVAL; + } + if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize ) { ERROR("ELF program headers extend beyond end of image."); -- 2.30.2